package com.suning.sawp.service.impl.biz;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.suning.sawp.dto.common.ReturnMsg;
import com.suning.sawp.dto.geography.SnCityInfo;
import com.suning.sawp.intf.biz.GeographyService;
import com.suning.vgs.follow.remote.intf.StoreManRemoteService;
import com.suning.vgs.wgg.service.intf.remote.bind.PpmClientRemoteService;

@Service("geographyService")
public class GeographyServiceImpl implements GeographyService {

    @Resource
    PpmClientRemoteService ppmClientRemoteService;
    
    @Resource
    StoreManRemoteService storeManRemoteService;
    
    @Override
    public ReturnMsg<SnCityInfo> getCityCodeByLocation(Double lat, Double lng) {
        ReturnMsg<SnCityInfo> msg = new ReturnMsg<SnCityInfo>();
        String cityCode = null;
        if (null != lat && null != lng) {
            cityCode = ppmClientRemoteService.getSnCityIdByLocation(lat, lng);
        }
        // 如果根据经纬度定位城市编码失败，则返回默认城市编码9173 南京
        cityCode = StringUtils.isNotBlank(cityCode) ? cityCode : "9173";
        // 获取城市名称
        String cityName = storeManRemoteService.getCityNameByB2cCityCode(cityCode);
        msg.setData(new SnCityInfo(cityCode, cityName));
        
        return msg;
    }

}
